package com.wuhao.shootclient.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wuhao.shootclient.R;
import com.wuhao.shootclient.adapter.ToaAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 校准dialog
 */
public class ThresholdDialog extends Dialog implements View.OnClickListener {


    //    @BindView(R.id.et_threshold)
    EditText etThreshold;
    EditText etThresholdBelend;
    //    @BindView(R.id.bt_threshold)
    Button btThreshold;
    //    @BindView(R.id.rv_seismic_value)
    RecyclerView rvSeismicValue;
    //    @BindView(R.id.bt_cancel)
    Button btCancel;

    private ToaAdapter toaAdapter;


    private Context context;

    private List<String> list = new ArrayList<>();


    private int Threshold = 0;
    private int ThresholdBlend = 0;
    private List<String> solist = new ArrayList<>();
    private TextView mTvnum;
    private TextView mTvnumBlend;
    private Button mBuqiang;
    private Button mBuqiang2;
    private Button mShouqiang;

    public ThresholdDialog(@NonNull Context context) {
        super(context, R.style.ThresholdDialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_threshold);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        initView();
        initData();
    }

    private void initView() {
        etThreshold = findViewById(R.id.et_threshold);
        etThresholdBelend = findViewById(R.id.et_thresholdBlend);
        etThreshold.setInputType(InputType.TYPE_CLASS_TEXT);
        etThreshold.setRawInputType(InputType.TYPE_CLASS_NUMBER);
        etThresholdBelend.setInputType(InputType.TYPE_CLASS_TEXT);
        etThresholdBelend.setRawInputType(InputType.TYPE_CLASS_NUMBER);
        btThreshold = findViewById(R.id.bt_threshold);
        rvSeismicValue = findViewById(R.id.rv_seismic_value);
        btCancel = findViewById(R.id.bt_cancel);
        mTvnum = findViewById(R.id.tv_threshold_end);
        mTvnumBlend = findViewById(R.id.tv_threshold_end_blend);
        mBuqiang = findViewById(R.id.bt_buqiang);
        mBuqiang2 = findViewById(R.id.bt_buqiang2);
        mShouqiang = findViewById(R.id.bt_shouqiang);
        btThreshold.setOnClickListener(this);
        btCancel.setOnClickListener(this);
        mBuqiang.setOnClickListener(this);
        mBuqiang2.setOnClickListener(this);
        mShouqiang.setOnClickListener(this);

    }

    private void initData() {
        if (list != null && list.size() != 0) {
            rvSeismicValue.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
            toaAdapter = new ToaAdapter(list);
            rvSeismicValue.setAdapter(toaAdapter);
            rvSeismicValue.scrollToPosition(toaAdapter.getItemCount() - 1);
            mTvnum.setText(Threshold + "");
            mTvnumBlend.setText(ThresholdBlend+"");
        }
    }

    public void setListRefresh(List<String> list) {
        toaAdapter.setNewData(list);
        rvSeismicValue.scrollToPosition(toaAdapter.getItemCount() - 1);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_threshold:
                onClickButListener.onButDownClick(etThreshold.getText().toString(),etThresholdBelend.getText().toString());
                break;
            case R.id.bt_cancel:
                this.dismiss();
                break;
            case R.id.bt_shouqiang:
                onClickButListener.onButDownClick("1100000","30");
                break;
            case R.id.bt_buqiang:
                onClickButListener.onButDownClick("3100000","30");
                break;
            case R.id.bt_buqiang2:
                onClickButListener.onButDownClick("5000000","30");
                break;
        }
    }


    public interface OnClickButListener {
        /**
         * 列表点击
         */
        public void onButDownClick(String threshold,String thresholdBelend);
    }

    public OnClickButListener onClickButListener;

    public ThresholdDialog setButOnClickListener(OnClickButListener onClickButListener) {
        this.onClickButListener = onClickButListener;
        return this;
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public List<String> getSolist() {
        return solist;
    }

    public void setSolist(List<String> solist) {
        this.solist = solist;
    }

    public int getThreshold() {
        return Threshold;
    }

    public void setThreshold(int threshold) {
        Threshold = threshold;
    }

    public void setThresholdblend(int thresholdblend) {
        this.ThresholdBlend = thresholdblend;
    }

    public int getThresholdblend() {
        return ThresholdBlend;
    }

}
